import { defineStore } from "pinia";
import { reqLogin } from "@/api/user.ts";
import { ElMessage } from "element-plus";
import { get_token,set_token } from "@/utils/cache.ts";

const useUseStore = defineStore('User',{
    state:() => {
        return{
            token :localStorage.getItem("vite-token"),
        }
    },
    actions:{
        async userLogin(loginForm?:any){
            const { data,code } = await reqLogin(loginForm)
            if(code === 200){
                this.token = data.token as string;
                set_token(data.token)
                return 'ok'
            }else {
                ElMessage.error(data.message);
                return Promise.reject(new Error(data.message));
            }
        }
    },
    getters:{

    }
})
export default useUseStore